package ua.com.fesvlast.hotel.model.commands;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ua.com.fesvlast.hotel.controller.managers.ConfigurationManager;
import ua.com.fesvlast.hotel.controller.managers.MessageManager;
import ua.com.fesvlast.hotel.model.dao.DAOFactory;

import ua.com.fesvlast.hotel.model.enteties.HotelRooms;

public class ChosenRoomCommand implements ICommand{
	
	
	
	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String page =null;
		HotelRooms room =new HotelRooms();
		int id=Integer.valueOf(request.getParameter("id"));
		room=DAOFactory.getHotelsRoomsDAO().getChosenRoom(id);
		
		if(room !=null){
			request.setAttribute("room", room);
			page=ConfigurationManager.getInstance().getProperty(ConfigurationManager.HOTEL_CHOSEN_ROOM);
		}else{
			request.setAttribute("errorMessage", MessageManager.getInstance().getProperty(
					MessageManager.LOGIN_ERROR_MESSAGE));
			
			page=ConfigurationManager.getInstance().getProperty(
					ConfigurationManager.ERROR_PAGE_PATH);
		}
		return page;
	}

}
